package com.fz.us.admin.base.service.impl;

import com.fz.us.admin.base.bean.search.Search;
import com.fz.us.admin.base.dao.MongoBaseDao;
import com.fz.us.admin.base.bean.search.result.SearchResult;
import com.fz.us.admin.base.entity.MongoEntity;
import com.fz.us.admin.base.service.MongoBaseService;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * Service实现类 - mongodb Service实现类基类
 * ============================================================================
 * 版权所有 2016 。
 *
 * @author fallenpanda
 * @version 1.0 2016-07-19 。
 * ============================================================================
 */
@Service
public abstract class MongoBaseServiceImpl<T extends MongoEntity, PK extends Serializable> implements MongoBaseService<T,PK> {

    private MongoBaseDao<T, PK> mongoBaseDao;

    public abstract MongoBaseDao<T, PK> getMongoBaseDao();

    public void setMongoBaseDao(MongoBaseDao<T, PK> mongoBaseDao) {
        this.mongoBaseDao = mongoBaseDao;
    }

    public List<T> find(Query query) {
        return getMongoBaseDao().find(query);
    }

    public T findOne(Query query) {
        return getMongoBaseDao().findOne(query);
    }

    public void update(Query query, Update update) {
        getMongoBaseDao().update(query,update);
    }

    public T save(T entity) {
        return getMongoBaseDao().save(entity);
    }

    public T findById(String id) {
        return getMongoBaseDao().findById(id);
    }

    public T findById(String id, String collectionName) {
        return getMongoBaseDao().findById(id,collectionName);
    }

    public long count(Query query) {
        return getMongoBaseDao().count(query);
    }

    public SearchResult findBySearch(Search search) {
        return getMongoBaseDao().findBySearch(search);
    }

}
